*****REPLACE THE WORKING DIRECTORY WITH THE LOCATION THE FILES ARE SAVED****
cd "C:\Users\PhotonUser\My Files\Home Folder\"
****************************************************************************

********************Figure 3: 1.6 billion jackpot graph*********************
import excel "all_states_JtJ.xlsx", sheet("Sheet1") firstrow clear

sort state date
collapse (mean) jackpot cash (sum) standard jtj megaplier , by(date)
gen sales = standard+jtj+megaplier
format sales %12.0g

twoway (scatter jackpot date, color(blue) msymbol(triangle) c(1) yaxis(1)) (scatter sales date, color(red) msymbol(circle) c(1) yaxis(2)) if date>td(26jul2018) & date<td(24oct2018), ///
graphregion(color(white)) ///
xlabel(,format(%tdMonDD)) ///
xtitle("Draw Date") ///
ylabel(0 200000000 "$200m" 400000000 "$400m" 600000000 "$600m" 800000000 "$800m", axis(2) labcolor(red)) ///
ytitle("Draw Sales", axis(2) color(red)) ///
ylabel(0 400000000 "$400m" 800000000 "$800m" 1200000000 "$1.2b" 1600000000 "$1.6b", axis(1) labcolor(blue)) ///
ytitle("Jackpot", axis(1) color(blue)) legend(label(1 "Jackpot") label(2 "Draw Sales") pos(6) ring(3))


********************Figure 4: Sales Percentages Graph*********************
import excel "all_states_JtJ.xlsx", sheet("Sheet1") firstrow clear

sort state date

keep if state=="DC" | state=="GA" | state=="IN" | state=="KS" | state=="KY" | state=="NE" | state=="NJ" | state=="NM" | state=="NY" | state=="SD" | state=="TX" | state=="VA" | state=="WI" | state=="WV" | state=="WY"

collapse (mean) jackpot cash (sum) standard jtj megaplier , by(date)

gen sales = standard+jtj+megaplier
gen s_sales=100*standard/sales
gen m_sales=100*megaplier/sales
gen j_sales=100*jtj/sales
gen jj=jtj/jackpot
gen min_jackpot=40000000
gen rollover=0
replace rollover=jackpot[_n-1] if jackpot != min_jackpot
gen ln_jtj=ln(jtj)
gen ln_rollover=ln(rollover)
replace ln_rollover=0 if rollover==0
gen ln_jackpot=ln(jackpot)
gen ln_sales=ln(sales)
gen time=_n

twoway (line m_sales date, color(blue) c(1) yaxis(1)) (line j_sales date, lpattern(dash) color(blue) c(1) yaxis(1)) (line s_sales date, color(red) c(1) yaxis(2)) if date>td(26jul2018) & date<td(24oct2018), ///
graphregion(color(white)) ///
xlabel(,format(%tdMonDD)) ///
xtitle("Draw Date") ///
ylabel(, axis(1) labcolor(blue)) ///
ytitle("Percent", axis(1) color(blue)) ///
ylabel(, axis(2) labcolor(red)) ///
ytitle("Percent", axis(2) color(red)) ///
legend(label(1 "Megaplier") label(2 "Just the Jackpot") label(3 "Base") pos(6) ring(3))


********************Figure W1: WRWM Parameter Predictions*********************
import excel "wrwm_parameters.xlsx", sheet("Sheet1") firstrow clear

twoway (scatter sw1 su1, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw1 mu1, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw1 ju1, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$40 Million Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm1.pdf", as(pdf) name("Graph") replace

twoway (scatter sw2 su2, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw2 mu2, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw2 ju2, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$100 Million Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm2.pdf", as(pdf) name("Graph") replace

twoway (scatter sw3 su3, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw3 mu3, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw3 ju3, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$200 Million Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm3.pdf", as(pdf) name("Graph") replace

twoway (scatter sw4 su4, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw4 mu4, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw4 ju4, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$300 Million Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm4.pdf", as(pdf) name("Graph") replace

twoway (scatter sw5 su5, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw5 mu5, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw5 ju5, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$400 Million Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm5.pdf", as(pdf) name("Graph") replace

twoway (scatter sw6 su6, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw6 mu6, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw6 ju6, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$500 Million Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm6.pdf", as(pdf) name("Graph") replace

twoway (scatter sw7 su7, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw7 mu7, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw7 ju7, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$750 Million Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm7.pdf", as(pdf) name("Graph") replace

twoway (scatter sw8 su8, msize(small) msymbol(S) yaxis(1) xaxis(1) legend(label(1 "Standard")))  (scatter mw8 mu8, msize(small) msymbol(T) yaxis(1) xaxis(1) legend(label(2 "Megaplier"))) (scatter jw8 ju8, msize(large) msymbol(X) yaxis(1) xaxis(1) legend(label(3 "Just the Jackpot") rows(1)) graphregion(color(white)) title("$1 Billion Jackpot") ytitle("Winner Regret Parameter Rho") xtitle("Utility Parameter Alpha")) 
*graph export "wrwm8.pdf", as(pdf) name("Graph") replace


***************Table W4: Difference in Difference Consumer Inattention******************
import excel "all_states_JtJ.xlsx", sheet("Sheet1") firstrow clear

keep if state=="KS" | state=="NE"

sort state date
gen sales = standard+jtj+megaplier
gen s_sales=standard/sales
gen m_sales=megaplier/sales
gen j_sales=100*jtj/sales
gen jj=jtj/jackpot
gen min_jackpot=40000000
gen rollover=0
replace rollover=jackpot[_n-1] if jackpot != min_jackpot
gen ln_jtj=ln(jtj)
gen ln_rollover=ln(rollover)
gen ln_jackpot=ln(jackpot)
gen ln_sales=ln(sales)
gen time=_n
gen month=month(date)
gen year=year(date)
gen tickets=standard/2 + megaplier/3 + jtj/3

gen treat=0 if date<td(02nov2018)
replace treat=1 if date>td(02nov2018)
replace treat=. if date==td(03may2019)
gen treat2=0 if date<td(03may2019)
replace treat2=1 if date>td(03may2019)
replace treat2=. if date==td(02nov2018)
gen ks=0
replace ks=1 if state=="KS"

*reg jtj ks##treat, r
*reg jtj ks##treat2, r

reg j_sales ks##treat, r
reg j_sales ks##treat2, r

*reg jj ks##treat, r
*reg jj ks##treat2, r

/* $150 shift to jtj*/
gen s1=standard
replace s1=standard-150 if treat==1 & ks==1
gen j1=jtj
replace j1=jtj+150 if treat==1 & ks==1
gen tot=s1+j1+megaplier
gen j_s=100*j1/tot
reg j_s ks##treat, r


***************Financial Constraints Elasticities******************
import excel "NY_megamillions_megaplier_jtj.xlsx", sheet("Sheet1") firstrow clear

drop if date<td(19oct2013)
drop if date>td(03apr2020)

gen period=1
replace period=2 if date>=td(31oct2017)
replace jtj=0 if missing(jtj)

gen megaplier=2*ny_megaplier
replace megaplier=3*ny_megaplier if period==2
gen standard=ny_standard-megaplier
gen total=standard+megaplier+jtj

gen tickets_megaplier=ny_megaplier
gen tickets_standard=standard-megaplier
replace tickets_standard=(standard-megaplier)/2 if period==2
gen tickets_jtj=jtj/3
gen tickets=tickets_standard+tickets_megaplier+tickets_jtj

gen min_jackpot=0
replace min_jackpot=1 if (period==1 & jackpot==15000000) | (period==2 & jackpot==40000000)

sort period
by period: sum tickets* if min_jackpot==1

*gen meg_tot=megaplier/total
*gen meg_tick=tickets_megaplier/tickets
*by period: sum meg_tot if min_jackpot==1
*by period: sum meg_tick if min_jackpot==1

***************Status Quo Bias******************
import excel "NY_megamillions_megaplier_jtj.xlsx", sheet("Sheet1") firstrow clear

gen megaplier=2*ny_megaplier
replace megaplier=3*ny_megaplier if date>=td(31oct2017)
gen standard=ny_standard-megaplier
replace jtj=0 if missing(jtj)
gen total=standard+megaplier+jtj
gen meg_tot=megaplier/total

sum meg_tot if meg_tot>0 & date<td(19oct2013), det
